package com.tailyou.hms.firstapp.act;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.appcompat.app.AppCompatActivity;

import com.tailyou.hms.firstapp.R;

//登录页面
public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        // 获取SharedPreferences实例
        SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);

        CheckBox cbAutoLogin = findViewById(R.id.cbAutoLogin);
        cbAutoLogin.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                //SharedPreferences提交数据
                sp.edit().putBoolean("AutoLogin",isChecked).commit();
            }
        });
        //SharedPreferences获取数据
        boolean autoLogin = sp.getBoolean("AutoLogin", false);
        cbAutoLogin.setChecked(autoLogin);

        Button btnLogin = findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //执行登录操作
                startActivity(new Intent(LoginActivity.this, TxtWdgActivity.class));
            }
        });
    }

}